#include "Flyweight.h"

Flyweight::Flyweight()
{
	m_hTexture = SGD::INVALID_HANDLE;
	AddRef();
}

Flyweight::Flyweight(BaseObject& owner)
{
	m_pOwner = &owner;
	AddRef();
}

Flyweight::~Flyweight()
{

}

void Flyweight::AddRef()
{
	++m_unRefCount;
}

void Flyweight::Release()
{
	--m_unRefCount;

	if (m_unRefCount == 0)
	{
		UnloadTexture();
		delete this;
	}
}

void Flyweight::SetImageID(const char * str)
{ 
	m_szImageID = str; 
	
}

void Flyweight::LoadTexture()
{
	m_hTexture = SGD::GraphicsManager::GetInstance()->LoadTexture(m_szImageID.c_str(), m_Color);


}

void Flyweight::UnloadTexture()
{
	SGD::GraphicsManager::GetInstance()->UnloadTexture(m_hTexture);


}
